package com.lyz.dataStructure.algorithm.zijietiaodong2019;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:03
 * @Description:
 **/

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/*
2
2 2
10 1
20 2
3 4
10 2
18 3
10 2
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i = 0;i<T;i++){
            int num = sc.nextInt();
            int time = sc.nextInt();
            int[] gameNum = new int[num];
            int[] gameTime = new int[num];
            for(int j =0;j<num;j++){
                gameNum[i] = sc.nextInt();
                gameTime[i] = sc.nextInt();
            }
            int maxTime = 0;
            int maxres = 0;
            int l =0;
            int r = gameTime.length-1;
            for(int k =0;k<gameTime.length;k++){
                if((gameTime[l]+gameTime[r])>maxTime&&(gameTime[l]+gameTime[r])<=time){
                    maxTime = gameTime[l]+gameTime[r];
                    maxres = gameNum[l]+gameNum[r];
                }
                l++;
                r++;
            }
            list.add(maxres);
        }
        for(int i =0;i<list.size();i++){
            System.out.println(list.get(i));
        }
    }
}
